package com.ruoyi.article.controller;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.article.domain.ZRelationArticleLabel;
import com.ruoyi.article.service.IZRelationArticleLabelService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章标签关系Controller
 * 
 * @author ruoyi
 * @date 2024-10-24
 */
@RestController
@RequestMapping("/article/relation_article_label")
public class ZRelationArticleLabelController extends BaseController
{
    @Autowired
    private IZRelationArticleLabelService zRelationArticleLabelService;

    /**
     * 查询文章标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZRelationArticleLabel zRelationArticleLabel)
    {
        startPage();
        List<ZRelationArticleLabel> list = zRelationArticleLabelService.list(new QueryWrapper<>(zRelationArticleLabel));
        return getDataTable(list);
    }

    /**
     * 导出文章标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:export')")
    @Log(title = "文章标签关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZRelationArticleLabel zRelationArticleLabel)
    {
        List<ZRelationArticleLabel> list = zRelationArticleLabelService.list(new QueryWrapper<>(zRelationArticleLabel));
        ExcelUtil<ZRelationArticleLabel> util = new ExcelUtil<ZRelationArticleLabel>(ZRelationArticleLabel.class);
        util.exportExcel(response, list, "文章标签关系数据");
    }

    /**
     * 获取文章标签关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(zRelationArticleLabelService.getById(id));
    }

    /**
     * 新增文章标签关系
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:add')")
    @Log(title = "文章标签关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZRelationArticleLabel zRelationArticleLabel)
    {
        return toAjax(zRelationArticleLabelService.save(zRelationArticleLabel));
    }

    /**
     * 修改文章标签关系
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:edit')")
    @Log(title = "文章标签关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZRelationArticleLabel zRelationArticleLabel)
    {
        return toAjax(zRelationArticleLabelService.updateById(zRelationArticleLabel));
    }

    /**
     * 删除文章标签关系
     */
    @PreAuthorize("@ss.hasPermi('article:relation_article_label:remove')")
    @Log(title = "文章标签关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zRelationArticleLabelService.removeByIds(Arrays.asList(ids)));
    }
}
